<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\api\model\house\HouseOrder as HouseOrderModel;
use addons\epay\library\Service;

class Housemanageorder extends Api
{

    protected $noNeedRight = ['*'];


    //业主的整屋订单列表
    public function lists()
    {
        $order_model = new HouseOrderModel();

        $data = [
            'owner_id'=>$this->auth->id,
            'order_status'=>input('order_status','all'),
            'order_type'=>1
        ];

        $list = $order_model->getManageOrderPageList($data);

        $this->success('',$list);
    }

    //业主的拼房订单列表
    public function pinlists()
    {
        $order_model = new HouseOrderModel();

        $data = [
            'owner_id'=>$this->auth->id,
            'order_status'=>input('order_status','all'),
            'order_type'=>2
        ];

        $list = $order_model->getManageOrderPageList($data);

        $this->success('',$list);
    }

    //业主的换房订单列表
    public function changelists()
    {
        $order_model = new HouseOrderModel();

        $data = [
            'owner_id'=>$this->auth->id,
            'order_status'=>input('order_status','all'),
            'order_type'=>3
        ];

        $list = $order_model->getManageOrderPageList($data);

        $this->success('',$list);
    }

    //详情
    public function changeinfo()
    {
        $model = new HouseOrderModel();
        $order_id = input('order_id',0);

        $res = $model->getOrderInfo($order_id);
        $this->success('',$res);
    }


    //详情
    public function pininfo()
    {
        $model = new HouseOrderModel();
        $order_id = input('order_id',0);

        $res = $model->getGroupOrderInfo($order_id);
        $this->success('',$res);
    }

    //详情
    public function info()
    {
        $model = new HouseOrderModel();
        $order_id = input('order_id',0);

        $res = $model->getOrderInfo($order_id);
        $this->success('',$res);
    }

    //已入住
    public function checkin()
    {
        try {
            $model = new HouseOrderModel();
            $order_id = input('order_id',0);

            $res = $model->orderManageCheckin($order_id);

        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('提交成功',$res);
    }

    //确认退房
    public function checkout()
    {
        try {
            $model = new HouseOrderModel();
            $order_id = input('order_id',0);

            $res = $model->orderOwnerCheckout($order_id);

        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('提交成功',$res);
    }

    //确认订单完成
    public function confirm()
    {
        try {
            $model = new HouseOrderModel();
            $order_id = input('order_id',0);

            $res = $model->orderOwnerConfirm($order_id);

        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('提交成功',$res);
    }

}